package com.beiing.tianshuai.tianshuai.freshnews.presenter;

import com.beiing.tianshuai.tianshuai.dongtai.CallBack;
import com.beiing.tianshuai.tianshuai.entity.DiscoveryIsPraiseBean;
import com.beiing.tianshuai.tianshuai.entity.DiscoveryPraiseBean;
import com.beiing.tianshuai.tianshuai.entity.FreshNewsListBean;
import com.beiing.tianshuai.tianshuai.freshnews.model.DiscoveryModel;
import com.beiing.tianshuai.tianshuai.freshnews.model.DiscoveryModelImpl;
import com.beiing.tianshuai.tianshuai.freshnews.view.DiscoveryViewImpl;

/**
 * Created by magikliu on 2017/7/7.
 */

public class DiscoveryPresenter implements DiscoveryPresenterImpl{

    private DiscoveryModelImpl mModel;
    private DiscoveryViewImpl mView;

    public DiscoveryPresenter(DiscoveryViewImpl mView) {
        this.mView = mView;
        this.mModel = new DiscoveryModel();
    }

    @Override
    public void getDiscovery(String userid, int page, int num, int picnum, final int type) {
//        mView.showProgress();
        mModel.getDiscoverys(userid, page, num, picnum, new CallBack<FreshNewsListBean>() {

            @Override
            public void result(FreshNewsListBean bean) {
//                mView.hideProgress();
                if (type == 0){
                    mView.showDiscovery(bean.getData());
                } else {
                    mView.refreshDiscovery(bean.getData());
                }

            }

            @Override
            public void error(Throwable e) {
                mView.showError(0);
            }
        });
    }

    @Override
    public void getDiscoveryIsPraise(String u_id, String f_id) {
        mModel.getDiscoveryIsPraise(u_id, f_id, new CallBack<DiscoveryIsPraiseBean>() {

            @Override
            public void result(DiscoveryIsPraiseBean bean) {
                mView.showIsPraised(bean);
            }

            @Override
            public void error(Throwable e) {
                mView.showError(1);
            }
        });
    }

    @Override
    public void praiseDiscovery(String u_id, String f_id) {
        mModel.praiseDiscovery(u_id, f_id, new CallBack<DiscoveryPraiseBean>() {
            @Override
            public void result(DiscoveryPraiseBean bean) {

            }

            @Override
            public void error(Throwable e) {
                mView.showError(2);
            }
        });
    }

}

